<?
/*
 * emarket - a website to create your own online-shop.  
 * Copyright (C) 2009  Frédéric Delorme
 *
 * This file is part of emarket.
 *
 * emarket is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * emarket is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with emarket.  If not, see <http://www.gnu.org/licenses/>.
 *
 * To contact me: frederic.delorme@gmail.com
 * to see some information on te project : http://code.google.col/p/os-emarket/
 *
 */
/**
 * Configuration File access manager class.
 * <p>This class is dedicated to acceding the config.ini file containing the 
 * web application parameters.</p>
 * <p><u>Note:</u><br/>
 * This class can't use the Debug class functionalities, because it is loading the Debug Object configuration.</p>
 * @author frederic
 *
 */
class Configuration{
	/**
	 * Singleton nstance.
	 * @var Configuration
	 */
	static private $_instance;
	/**
	 * Values of the configuration file
	 * @var array() of strings.
	 */
	private static $config;
	
	/**
	 * Default constructor, reading the config file.
	 * @return unknown_type
	 */
	public function __construct(){
		if(!isset(self::$config)){
			self::$config = parse_ini_file("webapp/configuration/config.ini",true);
		}
	}
	
	/**
	 * retrieving a value of a parameter ($group/$key).
	 * @param $group
	 * @param $key
	 * @param $defaultvalue
	 * @return String.
	 */
	public function getParam($group,$key,$defaultvalue=""){
		if($key!=""){
			if(!empty(self::$config[$group]) && !empty(self::$config[$group][$key])){
				return self::$config[$group][$key];
			}else{
				return $defaultvalue;
			}
		}else if($group!=""){ 
			return self::$config[$group];
		}else if($defaultvalue!=""){
			return $defaultvalue;
		}else{
			return -1;
		}
	}
	/**
	 * Return the state of a boolean parameter. Compare the ($group/$key) parameter
	 * to an array of value, determin ing the state for the parameter.
	 * To a parameter to be 'activiate', it must be equal to one the these values:
	 * <ul>
	 * 	<li>on</li>
	 * 	<li>ON</li>
	 * 	<li>1</li>
	 * 	<li>true</li>
	 * 	<li>TRUE</li>
	 * </ul>
	 * @param $group
	 * @param $key
	 * @return boolean value, true or false.
	 */
	public function isActive($group,$key){
		return in_array($this->getParam("system","rewrite"),array("on","ON","1","true"));
	}
	public function getInstance(){
		if(!self::$_instance){
			self::$_instance = new Configuration();
		}
		return self::$_instance;
	}
}
?>